package com.easy.common.jdbc;

public class DymaticCondition {

	private StringBuffer buffer = new StringBuffer(" ");

	public DymaticCondition addCondition(String key, String value) {
		if (value != null && !"".equals(value.trim()) && key != null
				&& !"".equals(key)) {
			
			buffer.append(key.replace("?", value)).append(" ");
		}

		return this;
	}
	
	public DymaticCondition addCondition(String key, String... values) {
		if (values != null) {
			for (int i = 0; i < values.length; ++i) {
				String value = values[i];
				
				if (value != null && !"".equals(value.trim()) && key != null
						&& !"".equals(key)) {
					
					key = key.replace("{"+i+"}", value);
				} else {
					return this;
				}
			}
		}
		
		buffer.append(key).append(" ");
		return this;
	}

	public String toString() {
		return buffer.toString();
	}
}
